<template>
	<uni-popup ref="popup" type="bottom">
		<view class="bg-white padding-sm radiusTop" style="">
			<view style="display: flex;  justify-content: space-between;" class="margin-bottom-sm">
				<view>
					<view class=" font-34rpx">选择位置与门店</view>
					<view class=" font-13">{{location.address}}</view>
				</view>
				<view @click="close()">关闭</view>
			</view>
			<scroll-view style="height: 700rpx;" scroll-y>
				<view v-for="item in list" @click="selectStore(item)">
					<storeItem :data="item"></storeItem>
					<view style="border-bottom:1px solid #ccc"></view>
				</view>
			</scroll-view>
		</view>

	</uni-popup>
</template>

<script>
	import {
		listByDistance10
	} from "@/api/shop/shopconfig/ShopConfigManagementApi.js"
	export default {
		name: "selectStorePopup",
		data() {
			return {
				location: {
					address: "加载中..."
				},
				list: []
			};
		},
		onShow() {

		},
		methods: {
			open() {
				this.init()
				this.$refs.popup.open()
				this.listByDistance10()
			},
			close() {
				this.$refs.popup.close()
			},

			async listByDistance10() {
				this.list = []
				let location = this.$storage.getItem("location")
				if (location == null) {
					uni.showModal({
						title: "提示",
						content: "当前位置未知,请先授权位置信息",
						showCancel: false,
					})
					return
				}
				let {
					data
				} = await listByDistance10({
					lat: location.latitude,
					lon: location.longitude
				})
				this.list = data
			},
			selectStore(data) {
				this.$emit("setCurrentShop", data)
				this.$storage.setItem("currentShop", data)
				this.$refs.popup.close()
			},

			init() {
				this.location = this.$storage.getItem("location")

			}

		}
	}
</script>

<style>
	.toTop {
		bottom: calc(var(--window-bottom));
	}
</style>